package com.yqya.async.task.async;

import java.lang.reflect.Method;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;

/**
 * 异步方法异常处理器
 *
 * @author Kevin
 * @date 2019-07-16
 */
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(AsyncExceptionHandler.class);

    @Override
    public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
        logger.error("+++++ Async method has uncaught exception, params:{}" + Arrays.toString(objects));

        if (throwable instanceof AsyncException) {
            AsyncException asyncException = (AsyncException) throwable;
            logger.error("+++++ asyncException: " + asyncException.getMessage());
        }

        logger.error("+++++ Exception: ", throwable);
    }

}
